(function(factory) {
  if (typeof define === "function" && define.amd) {
    define(["app", "echarts"], function(app) {
      factory(app);
    });
  } else {
    factory(angular.module("ngEcharts", []));
  }
})(function factory(module) {
  module
    .directive("linebarChart", [
      function() {
        return {
          restrict: "EA",
          scope: {
            theme: "@?",
            chartType: "=?",
            bgColor: "=?",
            colors: "=?",
            loading: "=?",
            title: "=?",
            titlePosition: "=?",
            titleColor: "=?",
            titleSize: "=?",
            tipType: "=?",
            closeTooltip: "=?",
            legend: "=?",
            legendIcon: "=?",
            legendPosition: "=?",
            legendVertical: "=?",
            closeLegend: "=?",
            openToolbox: "=?",
            data: "=",
            xdata: "=?",
            xType: "=?",
            closeXsplit: "=?",
            ydata: "=?",
            yType: "=?",
            closeYsplit: "=?",
            hoverAnimation: "=?",
            events: "=?",
            clickEvent: "=?",
            mouseoverEvent: "=?"
          },
          link: function(scope, element) {
            //定义配置模板
            var Option = {
              backgroundColor: "#fff",
              title: {
                text: "",
                left: "center",
                top: "10",
                textStyle: {
                  color: "#000",
                  fontSize: "16"
                }
              },
              tooltip: {
                trigger: "axis",
                show: true
              },
              legend: {
                orient: "horizontal",
                top: "bottom",
                left: "center",
                textStyle: {
                  color: "#000",
                  fontSize: "14"
                },
                data: []
              },
              grid: {
                show: false,
                containLabel: true,
                x: [],
                y: [],
                top: "15%",
                left: "0",
                width: "80%"
              },
              xAxis: {
                type: "category",
                boundaryGap: false,
                splitArea: {
                  show: false
                },
                splitLine: {
                  show: true
                },
                data: []
              },
              yAxis: {
                type: "value",
                splitArea: {
                  show: false
                },
                splitLine: {
                  show: true
                },
                data: []
              },
              toolbox: {
                show: false,
                left: "center",
                top: "8%",
                orient: "horizontal",
                feature: {
                  dataView: {
                    show: true
                  },
                  restore: {
                    show: true
                  },
                  saveAsImage: {
                    show: true
                  },
                  magicType: {
                    show: true,
                    type: ["line", "bar"]
                  },
                  dataZoom: {
                    show: false
                  },
                  brush: {
                    type: ["rect"]
                  }
                }
              },
              series: []
            };
            var line = {
              type: "line",
              name: "",
              smooth: true,
              label: {},
              data: []
            };
            var bar = {
              type: "bar",
              name: "",
              label: {},
              data: []
            };
            //监听系列数据变化
            scope.$watch(
              function() {
                return scope.data;
              },
              function() {
                refreshChart(scope, Option);
              },
              true
            );
            //监图表类型变化
            scope.$watch(
              function() {
                return scope.chartType;
              },
              function() {
                refreshChart(scope, Option);
              },
              true
            );
            //判断图表类型
            function setChartOption(option, scope, chart) {
              scope.chartType = scope.chartType ? scope.chartType : "line";

              if (scope.chartType === "line") {
                setLineData(option, scope, chart);
                // console.log('折线图',option);
              } else if (scope.chartType === "bar") {
                setBarData(option, scope, chart);
                console.log("柱状图", option);
              } else if (scope.chartType === "line-bar") {
                setLineBarData(option, scope, chart);
                console.log("复合图", option);
              }
            }
            //设置折线图数据
            function setLineData(option, scope, chart) {
              var dataLength = scope.data.length;
              if (dataLength == 0) {
                chart.clear();
                option.xAxis.splitLine.show = false;
              } else {
                option.xAxis.splitLine.show = true;
                chart.clear();
                angular.forEach(scope.data, function(item) {
                  var obj = angular.copy(line);
                  obj.name = item.name;
                  obj.data = item.data;
                  option.series.push(obj);
                });
                console.log("数据", option.series);
              }
            }
            //设置柱形图数据
            function setBarData(option, scope, chart) {
              option.xAxis.boundaryGap = true;
              var dataLength = scope.data.length;
              if (dataLength == 0) {
                chart.clear();
              } else {
                chart.clear();
                angular.forEach(scope.data, function(item) {
                  var obj = angular.copy(bar);
                  obj.name = item.name;
                  obj.data = item.data;
                  option.series.push(obj);
                });
                console.log("数据", option.series);
              }
            }
            //设置折线图/柱形图组合图形数据
            function setLineBarData(option, scope, chart) {
              option.xAxis.boundaryGap = true;
              var dataLength = scope.data.length;
              if (dataLength == 0) {
                chart.clear();
              } else {
                chart.clear();
                angular.forEach(scope.data, function(item) {
                  var obj = angular.copy(line);
                  obj.name = item.name;
                  obj.data = item.data;
                  option.series.push(obj);
                });
                angular.forEach(scope.data, function(item) {
                  var obj = angular.copy(bar);
                  obj.name = item.name;
                  obj.data = item.data;
                  option.series.push(obj);
                });
                // console.log('数据',option.series);
              }
            }
            //设置title
            function setTitle(option, scope) {
              //设置标题
              if (scope.title) {
                option.title.text = scope.title;
              }
              //设置标题位置
              if (scope.titlePosition) {
                option.title.top = scope.titlePosition[0];
                option.title.left = scope.titlePosition[1];
              }
              //设置标题样式
              if (scope.titleColor) {
                option.title.textStyle.color = scope.titleColor;
              }
              if (scope.titleSize) {
                option.title.textStyle.fontSize = scope.titleSize;
              }
            }
            //设置颜色
            function setColors(option, scope) {
              //设置背景
              if (scope.bgColor) {
                option.backgroundColor =
                  scope.bgColor || option.backgroundColor;
              }
              //自定义数据颜色
              if (scope.colors) {
                option.color = scope.colors;
              }
            }
            //设置图例组件
            function setLegend(option, scope) {
              if (scope.closeLegend) {
                option.legend.show = false;
              } else {
                //清空原图例数据
                option.legend.data = [];
                //设置图例数据
                angular.forEach(option.series, function(item) {
                  var obj = { name: "", icon: "" };
                  obj.name = item.name;
                  option.legend.data.push(obj);
                });
                //设置图例组件位置
                if (scope.legendPosition) {
                  option.legend.top = scope.legendPosition[0];
                  option.legend.left = scope.legendPosition[1];
                }
                //设置图例组件icon
                if (scope.legendIcon) {
                  var legendData = option.legend.data;
                  angular.forEach(legendData, function(item) {
                    item.icon = scope.legendIcon;
                  });
                }
                //图例组件是否为纵向布局，默认横向
                if (scope.legendVertical) {
                  option.legend.orient = "vertical";
                }
              }
            }
            //设置横坐标
            function setAxisx(option, scope) {
              if (scope.xdata) {
                option.xAxis.data = scope.xdata;
              }
              if (scope.xType) {
                option.xAxis.type = scope.xType;
              }
              if (scope.closeXsplit) {
                option.xAxis.splitLine.show = false;
              }
            }
            //设置纵坐标
            function setAxisy(option, scope) {
              if (scope.ydata) {
                option.yAxis.data = scope.ydata;
              }
              if (scope.yType) {
                option.yAxis.type = scope.yType;
              }
              if (scope.closeYsplit) {
                option.yAxis.splitLine.show = false;
              }
            }
            //设置tooltip提示框
            function setToolbox(option, scope) {
              //是否关闭鼠标移入时的提示框，默认开启
              if (scope.openToolbox) {
                option.toolbox.show = true;
              }
            }
            //设置工具栏
            function setTooltip(option, scope) {
              //是否关闭鼠标移入时的提示框，默认开启
              if (scope.closeTooltip) {
                option.tooltip.show = false;
              } else {
                //提示内容显示类型
                if (scope.tipType) {
                  option.tooltip.trigger = scope.tipType;
                }
              }
            }
            //注册事件
            function registerEvent(chart, scope) {
              //注册事件队列
              if (scope.events) {
                if (angular.isArray(scope.events)) {
                  angular.forEach(scope.events, function(value, key) {
                    for (var e in value) {
                      chart.on(e, value[e]);
                    }
                  });
                }
              }
              if (scope.clickEvent) {
                chart.on("click", scope.clickEvent);
              }
              if (scope.mouseoverEvent) {
                chart.on("mouseover", scope.mouseoverEvent);
              }
            }
            //图表更新，当监测的数据发生更改，执行该方法
            function refreshChart(scope, Option) {
              var theme = scope.theme ? scope.theme : "default";
              var chart = echarts.init(element[0], theme);
              var option = angular.copy(Option);
              //设置修改图表配置项
              setChartOption(option, scope, chart);
              //设置标题
              setTitle(option, scope);
              //设置颜色
              setColors(option, scope);
              //设置图例组件
              setLegend(option, scope);
              //设置横坐标
              setAxisx(option, scope);
              //设置纵坐标
              setAxisy(option, scope);
              //注册事件
              registerEvent(chart, scope);
              //设置tooltip
              setTooltip(option, scope);
              //设置工具栏
              setToolbox(option, scope);

              if (scope.loading) {
                chart.showLoading();
              }
              //为true时为数据加载完毕，渲染界面
              if (!scope.loading) {
                chart.setOption(option);
                chart.resize();
                chart.hideLoading();
              }
            }
          }
        };
      }
    ])
    .directive("mapChart", [
      function() {
        return {
          restrict: "EA",
          scope: {
            theme: "@?",
            bgColor: "=?",
            colors: "=?",
            loading: "=?",
            title: "=?",
            titlePosition: "=?",
            titleColor: "=?",
            titleSize: "=?",
            sData: "=?",
            sType: "=?",
            sName: "=?",
            mapData: "=",
            mapType: "=?",
            mapLink: "=?",
            mapSepara: "=?",
            combination: "=?",
            legendIcon: "=?",
            legendPosition: "=?",
            legendVertical: "=?",
            closeLegend: "=?",
            closeTooltip: "=?",
            layoutPosition0: "=?",
            layoutPosition1: "=?",
            layoutSize0: "=?",
            layoutSize1: "=?",
            hoverAnimation: "=?",
            events: "=?",
            clickEvent: "=?",
            mouseoverEvent: "=?"
          },
          link: function(scope, element) {
            var geo = {
              map: "china",
              roam: false,
              scaleLimit: {
                min: 1,
                max: 5
              },
              itemStyle: {
                normal: {
                  areaColor: "#CCCCCC",
                  borderColor: "#111"
                },
                emphasis: {
                  areaColor: "#FFD322"
                }
              },
              label: {
                normal: {
                  show: true,
                  color: "#000",
                  position: [50, 50]
                },
                emphasis: {
                  show: true,
                  color: "#fff"
                }
              },
              layoutCenter: ["50%", "50%"],
              layoutSize: "100%",
              regions: [
                {
                  name: "内蒙古",
                  label: {
                    normal: {
                      show: true,
                      color: "#000",
                      position: [50, 50]
                    },
                    emphasis: {
                      show: true,
                      color: "#fff",
                      position: "insideRight"
                    }
                  }
                }
              ],
              data: []
            };
            var seriesGeo = [
              {
                name: "",
                type: "scatter",
                coordinateSystem: "geo",
                data: [],
                symbolSize: 12,
                label: {
                  normal: {
                    show: false
                  },
                  emphasis: {
                    show: false
                  }
                },
                itemStyle: {
                  emphasis: {
                    color: "yellow",
                    borderColor: "yellow",
                    borderWidth: 2
                  }
                }
              }
            ];
            var seriesMapLink = [
              {
                type: "map",
                mapType: "china",
                roam: false,
                scaleLimit: {
                  min: 0.5,
                  max: 2
                },
                geoIndex: 0,
                label: {
                  normal: {
                    show: false,
                    color: "#000"
                  },
                  emphasis: {
                    show: true,
                    color: "#fff"
                  }
                },
                itemStyle: {
                  normal: {
                    areaColor: "#CCCCCC",
                    borderColor: "#111"
                  },
                  emphasis: {
                    areaColor: "#FFD322"
                  }
                },
                layoutCenter: ["30%", "50%"],
                layoutSize: "100%",
                data: []
              },
              {
                type: "map",
                mapType: "china",
                geoIndex: 0,
                label: {
                  normal: {
                    show: false,
                    color: "#000"
                  },
                  emphasis: {
                    show: true,
                    color: "#fff"
                  }
                },
                itemStyle: {
                  normal: {
                    areaColor: "#CCCCCC",
                    borderColor: "#111"
                  },
                  emphasis: {
                    areaColor: "#FFD322"
                  }
                },
                layoutCenter: ["80%", "50%"],
                layoutSize: "60%",
                data: []
              }
            ];
            var option = {
              backgroundColor: "#fff",
              title: {
                text: "",
                left: "center",
                top: "10",
                textStyle: {
                  color: "#000",
                  fontSize: "16"
                }
              },
              legend: {
                data: []
              },
              tooltip: {
                trigger: "item",
                formatter: function(params) {
                  return params.name;
                }
              },
              textStyle: {
                fontSize: 12
              },
              series: []
            };

            //监听系列数据变化
            scope.$watch(
              function() {
                return scope.sData;
              },
              function() {
                refreshChart(scope, option);
              },
              true
            );
            //监听地图数据变化
            scope.$watch(
              function() {
                return scope.mapData;
              },
              function() {
                refreshChart(scope, option);
              },
              true
            );

            //参数初始化
            function paramInit(scope) {
              //默认为非联动模式
              scope.mapLink = scope.mapLink ? scope.mapLink : false;
              //默认为不显示加载动画
              scope.loading = scope.loading ? scope.loading : false;
              //联动模式下，默认省市分离
              scope.mapSepara = scope.mapSepara ? scope.mapSepara : false;
            }
            //注册地图信息
            function registerMap(scope, mapType) {
              if (scope.mapData) {
                // console.log('注册地图信息',mapType,scope.mapData);
                echarts.registerMap(mapType, scope.mapData);
              }
            }
            //三级联动数据处理
            function mapLinkHandle(option, scope) {
              //改变地图类型,三级联动时启用
              if (scope.mapType && scope.mapLink) {
                if (scope.mapSepara) {
                  option.series[0].mapType = "china";
                  option.series[1].mapType = scope.mapType;
                } else {
                  option.series[0].mapType = scope.mapType;
                  option.series[1].mapType = null;
                }
              }
              //处理传递过来的地图数据，三级联动时启用
              if (scope.mapData && scope.mapLink) {
                var features = scope.mapData.features;
                var length = features.length;
                if (scope.mapSepara) {
                  option.series[1].data = [];
                } else {
                  option.series[0].data = [];
                }
                if (length == 34) {
                  angular.forEach(features, function(item) {
                    var obj = {
                      value: "",
                      name: "",
                      id: ""
                    };
                    obj.id = item.properties.id;
                    obj.name = item.properties.name;
                    option.series[0].data.push(obj);
                  });
                  console.log("联动数据处理", option);
                } else {
                  if (scope.mapSepara) {
                    // option.series[0].layoutCenter=['20%','50%'];
                    // option.series[0].layoutSize='70%';
                    // option.series[1].layoutCenter=['70%','50%'];
                    // option.series[1].layoutSize='80%';
                    angular.forEach(features, function(item) {
                      var obj = {
                        value: "",
                        name: "",
                        id: ""
                      };
                      obj.id = item.properties.id + "00";
                      obj.name = item.properties.name;
                      option.series[1].data.push(obj);
                    });
                  } else {
                    // option.series[0].layoutCenter=['45%','50%'];
                    // option.series[0].layoutSize='80%';
                    angular.forEach(features, function(item) {
                      var obj = {
                        value: "",
                        name: "",
                        id: ""
                      };
                      obj.id = item.properties.id + "00";
                      obj.name = item.properties.name;
                      option.series[0].data.push(obj);
                    });
                  }
                }
              }
            }
            //非三级联动,即设置geo配套数据
            function geoDrawChart(scope) {
              //设置图表类型,默认散点图
              if (scope.sType && !scope.mapLink) {
                option.series[0].type = scope.sType;
              }
              //设置图表类型,默认散点图
              if (scope.sName && !scope.mapLink) {
                option.series[0].type = scope.sName;
              }
              //在地图设置系列数据()
              if (scope.sData && !scope.mapLink) {
                option.series[0].data = scope.sData;
              }
            }
            //通过判断地图类型是否为联动,选择配置
            function setMapOption(option, scope) {
              //判断是否启用三级联动
              if (scope.mapLink) {
                delete option.geo;
                option.series = seriesMapLink;
                mapLinkHandle(option, scope);
              } else {
                option.geo = geo;
                option.series = seriesGeo;
                geoDrawChart(scope);
              }
            }
            //设置title
            function setTitle(option, scope) {
              //设置标题
              if (scope.title) {
                option.title.text = scope.title;
              }
              //设置标题位置
              if (scope.titlePosition) {
                option.title.top = scope.titlePosition[0];
                option.title.left = scope.titlePosition[1];
              }
              //设置标题样式
              if (scope.titleColor) {
                option.title.textStyle.color = scope.titleColor;
              }
              if (scope.titleSize) {
                option.title.textStyle.fontSize = scope.titleSize;
              }
            }
            //设置颜色
            function setColors(option, scope) {
              //设置背景
              if (scope.bgColor) {
                option.backgroundColor =
                  scope.bgColor || option.backgroundColor;
              }
              //自定义数据颜色
              if (scope.colors) {
                option.color = scope.colors;
              }
            }
            //设置图例组件
            function setLegend(option, scope) {
              //设置图例组件位置
              if (scope.legendPosition) {
                option.legend.top = scope.legendPosition[0];
                option.legend.left = scope.legendPosition[1];
              }
              //设置图例组件icon
              if (scope.legendIcon) {
                angular.forEach(seriesData, function(data, index) {
                  var length = seriesData.length;
                  for (var i = 0; i < length; i++) {
                    var obj = { name: "" };
                    obj.name = data.name;
                    legendData.push(obj);
                  }
                });
              }
              //图例组件是否为纵向布局，默认横向
              if (scope.legendVertical) {
                option.legend.orient = "vertical";
              }
            }
            //设置tooltip
            function setTooltip(option, scope) {
              //是否关闭鼠标移入时的提示框，默认开启
              if (scope.closeTooltip) {
                option.tooltip.show = false;
              }
            }
            //设置地图布局与大小
            function setLayout(option, scope) {
              if (scope.mapLink) {
                if (scope.layoutSize0) {
                  option.series[0].layoutSize = scope.layoutSize0;
                }
                if (scope.layoutPosition0) {
                  option.series[0].layoutCenter = scope.layoutPosition0;
                }
                if (scope.layoutSize1) {
                  option.series[1].layoutSize = scope.layoutSize0;
                }
                if (scope.layoutPosition1) {
                  option.series[1].layoutCenter = scope.layoutPosition1;
                }
              } else {
                if (scope.layoutSize0) {
                  option.geo.layoutSize = scope.layoutSize0;
                }
                if (scope.layoutPosition0) {
                  option.geo.layoutCenter = scope.layoutPosition0;
                }
              }
            }
            //注册事件
            function registerEvent(chart, scope) {
              //注册事件队列
              if (scope.events) {
                if (angular.isArray(scope.events)) {
                  angular.forEach(scope.events, function(value, key) {
                    for (var e in value) {
                      chart.on(e, value[e]);
                    }
                  });
                }
              }
              if (scope.clickEvent) {
                chart.on("click", scope.clickEvent);
              }
              if (scope.mouseoverEvent) {
                chart.on("mouseover", scope.mouseoverEvent);
              }
            }

            //图表更新，当监测的数据发生更改，执行该方法
            function refreshChart(scope, option) {
              var theme = scope.theme ? scope.theme : "default";
              var mapType = scope.mapType ? scope.mapType : "china";
              var chart = echarts.init(element[0], theme);
              //初始化参数
              paramInit(scope);
              //注册地图信息
              registerMap(scope, mapType);
              //判断地图是否为联动类型，进行对应数据配置
              setMapOption(option, scope);
              //设置标题
              setTitle(option, scope);
              //设置颜色
              setColors(option, scope);
              //设置图例组件
              setLegend(option, scope);
              //设置地图布局
              setLayout(option, scope);
              //注册事件
              registerEvent(chart, scope);
              //设置tooltip
              setTooltip(option, scope);
              //是否显示鼠标移入的动画效果
              if (scope.hoverAnimation) {
                option.series[0].hoverAnimation = true;
              }
              //是否显示数据加载时的动画
              if (scope.loading) {
                chart.showLoading();
              }
              //为true时为数据加载完毕，渲染界面
              if (!scope.loading) {
                chart.setOption(option);
                chart.resize();
                chart.hideLoading();
              }
            }
          }
        };
      }
    ])
    .directive("pieChart", [
      function() {
        return {
          restrict: "EA",
          scope: {
            theme: "@?",
            chartType: "=?",
            bgColor: "=?",
            colors: "=?",
            loading: "=?",
            title: "=?",
            titlePosition: "=?",
            titleColor: "=?",
            titleSize: "=?",
            tipType: "=?",
            closeTooltip: "=?",
            legend: "=?",
            legendIcon: "=?",
            legendPosition: "=?",
            legendVertical: "=?",
            closeLegend: "=?",
            openToolbox: "=?",
            data: "=",
            isRing: "=?",
            radius: "=?",
            labelInCenter: "=?",
            hoverAnimation: "=?",
            closeTooltip: "=?",
            events: "&?"
          },
          link: function(scope, element) {
            var option = {
              backgroundColor: "#fff",
              title: {
                text: "扇形图",
                subtext: "",
                top: "0",
                left: "center",
                x: "center",
                textStyle: {
                  color: "#000",
                  fontSize: 24
                }
              },
              tooltip: {
                show: true,
                trigger: "item",
                formatter: "{b}: {c} ({d}%)"
              },
              legend: {
                left: "center",
                top: "bottom",
                bottom: "10",
                orient: "horizontal",
                textStyle: {
                  fontSize: 14
                },
                data: []
              },
              toolbox: {
                show: false,
                left: "center",
                top: "8%",
                orient: "horizontal",
                feature: {
                  dataView: {
                    show: true
                  },
                  restore: {
                    show: true
                  },
                  saveAsImage: {
                    show: true
                  },
                  magicType: {
                    show: true,
                    type: ["line", "bar"]
                  },
                  dataZoom: {
                    show: false
                  },
                  brush: {
                    type: ["rect"]
                  }
                }
              },
              series: [
                {
                  type: "pie",
                  hoverAnimation: false,
                  selectedOffset: "10",
                  hoverOffset: "10",
                  radius: [0, "80%"],
                  center: ["50%", "50%"],
                  textStyle: {
                    color: "#fff",
                    fontSize: 16
                  },
                  label: {
                    normal: {
                      show: true,
                      position: "inside",
                      formatter: " {b}\n {d}%"
                    },
                    emphasis: {
                      show: true,
                      verticalAlign: "middle",
                      textStyle: {
                        fontSize: "12",
                        fontWeight: ""
                      }
                    }
                  },
                  data: []
                }
              ]
            };
            //监听数据变化
            scope.$watch(
              function() {
                return scope.data;
              },
              function() {
                refreshChart(option, scope);
              },
              true
            );
            //更新数据函数
            function refreshChart(option, scope) {
              var theme = scope.theme ? scope.theme : "default";
              var chart = echarts.init(element[0], theme);
              //设置数据
              setData(option, scope);
              //設置標題
              setTitle(option, scope);
              //设置为圆环
              setRing(option, scope);
              //设置颜色
              setColors(option, scope);
              //设置图例组件
              setLegend(option, scope);
              //设置工具栏
              setToolbox(option, scope);
              //设置tooltip提示框
              setTooltip(option, scope);
              //注册事件
              registerEvent(chart, scope);
              //是否显示数据加载时的动画
              if (scope.loading) {
                chart.showLoading();
              }
              //为true时为数据加载完毕，渲染界面
              if (!scope.loading) {
                chart.setOption(option);
                chart.resize();
                chart.hideLoading();
              }
            }
            //设置数据
            function setData(option, scope) {
              if (scope.data) {
                option.series[0].data = scope.data;
              }
            }
            //设置为圆环
            function setRing(option, scope) {
              //是否为圆环,该项设置为true为圆环，默认为扇形图
              if (scope.isRing) {
                option.series[0].radius[0] = "50%";
                //数据名称是否显示在中间，针对圆环使用
                if (scope.labelInCenter) {
                  option.series[0].label.normal.show = false;
                  option.series[0].label.normal.position = "center";
                  option.series[0].label.emphasis.textStyle.fontSize = "24";
                  option.series[0].label.emphasis.textStyle.fontWeight = "bold";
                }
              }
              //设置半径，默认80%
              if (scope.radius) {
                option.series[0].radius[1] = scope.radius;
              }
              //是否显示鼠标移入的动画效果
              if (scope.hoverAnimation) {
                option.series[0].hoverAnimation = true;
              }
            }
            //设置title
            function setTitle(option, scope) {
              //设置标题
              if (scope.title) {
                option.title.text = scope.title;
              }
              //设置标题位置
              if (scope.titlePosition) {
                option.title.top = scope.titlePosition[0];
                option.title.left = scope.titlePosition[1];
              }
              //设置标题样式
              if (scope.titleColor) {
                option.title.textStyle.color = scope.titleColor;
              }
              if (scope.titleSize) {
                option.title.textStyle.fontSize = scope.titleSize;
              }
            }
            //设置颜色
            function setColors(option, scope) {
              //设置背景
              if (scope.bgColor) {
                option.backgroundColor =
                  scope.bgColor || option.backgroundColor;
              }
              //自定义数据颜色
              if (scope.colors) {
                option.color = scope.colors;
              }
            }
            //设置图例组件
            function setLegend(option, scope) {
              if (scope.closeLegend) {
                option.legend.show = false;
              } else {
                //清空原图例数据
                option.legend.data = [];
                //设置图例数据
                angular.forEach(option.series, function(item) {
                  var obj = { name: "", icon: "" };
                  obj.name = item.name;
                  option.legend.data.push(obj);
                });
                //设置图例组件位置
                if (scope.legendPosition) {
                  option.legend.top = scope.legendPosition[0];
                  option.legend.left = scope.legendPosition[1];
                }
                //设置图例组件icon
                if (scope.legendIcon) {
                  var legendData = option.legend.data;
                  angular.forEach(legendData, function(item) {
                    item.icon = scope.legendIcon;
                  });
                }
                //图例组件是否为纵向布局，默认横向
                if (scope.legendVertical) {
                  option.legend.orient = "vertical";
                }
              }
            }
            //设置tooltip提示框
            function setToolbox(option, scope) {
              //是否关闭鼠标移入时的提示框，默认开启
              if (scope.openToolbox) {
                option.toolbox.show = true;
              }
            }
            //设置工具栏
            function setTooltip(option, scope) {
              //是否关闭鼠标移入时的提示框，默认开启
              if (scope.closeTooltip) {
                option.tooltip.show = false;
              } else {
                //提示内容显示类型
                if (scope.tipType) {
                  option.tooltip.trigger = scope.tipType;
                }
              }
            }
            //注册事件
            function registerEvent(chart, scope) {
              //注册事件队列
              if (scope.events) {
                if (angular.isArray(scope.events)) {
                  angular.forEach(scope.events, function(value, key) {
                    for (var e in value) {
                      chart.on(e, value[e]);
                    }
                  });
                }
              }
              if (scope.clickEvent) {
                chart.on("click", scope.clickEvent);
              }
              if (scope.mouseoverEvent) {
                chart.on("mouseover", scope.mouseoverEvent);
              }
            }
          }
        };
      }
    ]);
});
